<!--
 * @desc:
 * @Author: 钟强
 * @Date: 2021-12-02 09:46:39
 * @LastEditors: 钟强
 * @LastEditTime: 2021-12-03 16:16:39
-->
<template>
  <el-breadcrumb class="breadcrumb" separator="/">
    <transition-group name="breadcrumb">
      <el-breadcrumb-item v-for="(item,index) in breadcrumbData" :key="item.path">
      <span v-if="index === breadcrumbData.length -1" class="no-redirect">{{generateTitle(item.meta.title)}}</span>
      <a class="redirect" v-else @click.prevent="onLinkClick(item)">{{generateTitle(item.meta.title)}}</a>
    </el-breadcrumb-item>
    </transition-group>
  </el-breadcrumb>
</template>

<script setup>
import { ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useStore } from 'vuex'
import { generateTitle } from '../../utils/i18n'
const route = useRoute()
const breadcrumbData = ref([])
const getBreadcrumbData = () => {
  breadcrumbData.value = route.matched.filter(
    (item) => item.meta && item.meta.title
  )
}

watch(
  route,
  () => {
    getBreadcrumbData()
  },
  { immediate: true }
)

// 点击跳转
const router = useRouter()
const onLinkClick = item => {
  router.push(item.path)
}

// 将来需要进行主题替换，所以这里获取下动态样式
const store = useStore()
// eslint-disable-next-line
const linkHoverColor = ref(store.getters.cssVar.menuBg)

</script>

<style lang="scss" scoped>
.breadcrumb {
  display: inline-block;
  font-size: 14px;
  line-height: 50px;
  margin-left: 8px;

  .redirect{
    color: #666;
    font-weight: 600;
    &:hover{
      color: v-bind(linkHoverColor);
    }
  }

  ::v-deep .no-redirect {
    color: #97a8be;
    cursor: text;
  }
}
</style>
